package ware.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.util.ObjectUtils;
import ware.domain.WareInfo;
import ware.service.WareInfoService;
import ware.mapper.WareInfoMapper;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author panghu
 * @description 针对表【wms_ware_info(仓库信息)】的数据库操作Service实现
 * @createDate 2023-03-04 21:05:07
 */
@Service
public class WareInfoServiceImpl extends ServiceImpl<WareInfoMapper, WareInfo>
        implements WareInfoService {

    @Override
    public Page<WareInfo> querPage(Map<String, Object> params) {
        LambdaQueryWrapper<WareInfo> queryWrapper = getQueryWrapper(params);
        Page<WareInfo> wareInfoPage = new Page<>(Integer.parseInt((String) params.get("page")), Integer.parseInt((String) params.get("limit")));
        return this.baseMapper.selectPage(wareInfoPage, queryWrapper);

    }

    private LambdaQueryWrapper<WareInfo> getQueryWrapper(Map<String, Object> params) {
        LambdaQueryWrapper<WareInfo> wrapper = new LambdaQueryWrapper<>();
        if (!ObjectUtils.isEmpty(params.get("key"))) {
            Object key = params.get("key");
            wrapper.like(WareInfo::getName, key)
                    .or().eq(WareInfo::getId, key)
                    .or().like(WareInfo::getAddress, key)
                    .or().eq(WareInfo::getAreacode, key)
            ;
        }
        return wrapper;
    }


}




